package com.dwusoft.banks.tradeBank.exception;

import java.util.Locale;

import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;

import com.dwusoft.banks.tradeBank.common.utils.SpringBeanFactory;




/**
 * P2P应用异常
 * 异常文件errMsg.properties
 * @author yzj
 * @date 2014-02-25
 * @see  java.lang.RuntimeException
 * @see  ErrorCodeDefine
 * @see  ErrorConst
 */
public class P2PException extends RuntimeException {
	
	private static final long serialVersionUID = 6760665954578863306L;
	
	private String errCode; 
	private String message;
	private String errType;
	
    public P2PException(String errCode,Throwable t,String[] fixMsgs){
		super(t);
		this.errCode=errCode;	
		try {
			MessageSource ms = SpringBeanFactory.getBean("messageSource");
			this.message = ms.getMessage(errCode, fixMsgs, Locale.SIMPLIFIED_CHINESE);
		} catch (NoSuchMessageException ex) {
			ex.printStackTrace();
			this.message = "未知错误!";
		}
	}
    
    public P2PException(String errCode, String[] fixMsgs){
		this.errCode=errCode;	
		try {
			MessageSource ms = SpringBeanFactory.getBean("messageSource");
			this.message = ms.getMessage(errCode, fixMsgs, Locale.SIMPLIFIED_CHINESE);
		} catch (NoSuchMessageException ex) {
			ex.printStackTrace();
			this.message = "未知错误!";
		}
	}
    
    public P2PException(String errCode){
    	this.errCode=errCode;	
		try {
			MessageSource ms = SpringBeanFactory.getBean("messageSource");
			this.message = ms.getMessage(errCode, null, Locale.SIMPLIFIED_CHINESE);
		} catch (NoSuchMessageException ex) {
			ex.printStackTrace();
			this.message = "未知错误!";
		}
    }
    
    public P2PException(String errCode, String message){
    	this.errCode=errCode;	
		this.message = message;
    }
    
    public P2PException(String errCode, String message, String errType){
    	this.errCode=errCode;	
		this.message = message;
		this.errType = errType;
    }
    
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getErrCode() {
		return errCode;
	}
	public void setErrCode(String errCode) {
		this.errCode = errCode;
	}

	public String getErrType() {
		return errType;
	}

	public void setErrType(String errType) {
		this.errType = errType;
	}
	
}
